#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<memory>
#include<list>
#include<thread>
#include<mutex>
#include"shared_ptr.h"
using namespace std;
struct Node
{
	/*std::shared_ptr<Node> _next;
	std::shared_ptr<Node> _prev;*/
	std::weak_ptr<Node> _next;
	std::weak_ptr<Node> _prev;
	int _val;

	~Node()
	{
		cout << "~Node()" << endl;
	}
};

class A
{
public:
	A(int a1, int a2)
		:_a1(a1)
		, _a2(a2)
	{}
	A()
	{}
	~A()
	{
		cout << "~A()" << endl;
	}
	//private:
	int _a1 = 1;
	int _a2 = 1;
};
//int main()
//{
//	std::shared_ptr<Node> p1(new Node);
//	std::shared_ptr<Node> p2 (new Node);
//
//	cout << p1.use_count() << endl;
//	cout << p2.use_count() << endl;
//
//	p1->_next = p2;
//	p2->_prev = p1;
//
//	cout << p1.use_count() << endl;
//	cout << p2.use_count() << endl;
//	return 0;
//}
template<class T>
struct FreeFunc
{
	void operator()(T* ptr)
	{
		cout << "free:" << ptr << endl;
		free(ptr);
	}
};
int main()
{
	//std::shared_ptr<A[]> sp1(new A[10]);
	bit::shared_ptr<A> sp1(new A[10], [](A* ptr) { delete[] ptr; });
	bit::shared_ptr<int> sp2((int*)malloc(4), FreeFunc<int>());
	bit::shared_ptr<FILE> sp3(fopen("test.txt", "w"), [](FILE* ptr) {fclose(ptr); });

	bit::shared_ptr<A> sp4(new A);
	return 0;
}